class Solution {
public:
    int sum = 0;
    vector<int> arr1 = { 1,5,10,50,100,500,1000 };
    /*vector<char> arr2 = { 'I','V','X','L','C','D','M' };*/
    string arr2 = "IVXLCDM";
    int romanToInt(string s)
    {
        vector<int> ret;
        for (auto& r : s)
        {
            int pos = arr2.find(r);
            ret.push_back(arr1[pos]);
        }

        for (int i = 0; i < ret.size(); i++)
        {
            if (i + 1 < ret.size() && ret[i] < ret[i + 1])
                sum += -1 * ret[i];
            else
                sum += ret[i];
        }
        return sum;
    }
};